﻿using System;
using System.IO;
using System.Web.UI;

namespace mal.balades.Business.Web
{
    public class AdminsitrationPageBase : Page
    {
        #region Fields
        private ScriptManager scriptManager;


        #endregion

        #region Construction / Destruction

        #endregion

        #region enum, struct, class

        #endregion

        #region Properties
        public ScriptManager ScriptManager
        {
            get
            {
                if (scriptManager == null)
                    scriptManager = ScriptManager.GetCurrent(this.Page);
                return scriptManager;
            }

        }
        #endregion

        #region Methods
        protected void LoadJavascript()
        {

        }
        #endregion

        #region Events
        protected void Page_PreLoad(object sender, EventArgs e)
        {
            FileInfo file = new FileInfo(this.Request.PhysicalPath);

#if DEBUG
            //this.ScriptManager.CompositeScript.ScriptMode = ScriptMode.Release;

            foreach (FileInfo js in file.Directory.GetFiles("*.js"))
            {
                int index = js.FullName.IndexOf("\\Administration");
                string url = js.FullName.Substring(index).Replace("\\", "/");
                this.ScriptManager.Scripts.Add(new ScriptReference(url));
            }
#else
            this.ScriptManager.CompositeScript.ScriptMode = ScriptMode.Release;

            foreach (FileInfo js in file.Directory.GetFiles("*.js"))
            {
                int index = js.FullName.IndexOf("\\Administration");
                string url = js.FullName.Substring(index).Replace("\\", "/");
                this.ScriptManager.CompositeScript.Scripts.Add(new ScriptReference(url));
            }
#endif

            

            foreach (FileInfo service in file.Directory.GetFiles("*.svc"))
            {
                int index = service.FullName.IndexOf("\\Administration");
                string url = service.FullName.Substring(index).Replace("\\", "/");
                this.ScriptManager.Services.Add(new ServiceReference(url));
            }
        }
        #endregion


    }
}
